/**
 * Created with IntelliJ IDEA.
 * Description:
 * user:likai
 * Date:2022-11-29
 * Time:17:33
 */
class TreeNode{
    int val;
    TreeNode left;
    TreeNode right;
    public TreeNode(int val){
        this.val=val;
    }
}
class Solution {

    TreeNode ret = null;

    public void  ConvertTree(TreeNode root) {
        if (root == null) {
            return;
        }
        ConvertTree(root.left);
        root.left = ret;
        if(ret!=null){
            ret.right=root;
        }
        ret = root;
        ConvertTree(root.right);
    }
    public TreeNode Convert(TreeNode pRootOfTree) {
        if(pRootOfTree==null){
            return null;
        }
        ConvertTree(pRootOfTree);
        TreeNode head = pRootOfTree;
        while (head.left != null) {
            head = head.left;
        }
        return head;
    }
}
public class Test {
}
